home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection 1998 Fall: Game Toolkit / Disc.iso / SDKs / Apple Game Sprockets / InputSprocket / Sample Drivers / Common Driver Code / ISpPlugInUI.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-07-17  |  10.4 KB  |  340 lines  |  [TEXT/CWIE]

  1. /*************************************************************************************
  2.  
  3. File:      ISpPlugInUI.h
  4.  
  5. Copyright © 1996, 1997, 1998 Apple Computer, Inc., All Rights Reserved
  6.  
  7.  
  8. You may incorporate this sample code into your applications without
  9. restriction, though the sample code has been provided "AS IS" and the
  10. responsibility for its operation is 100% yours.  However, what you are
  11. not permitted to do is to redistribute the source as "DSC Sample Code"
  12. after having made changes. If you're going to re-distribute the source,
  13. we require that you make it clear in the source that the code was
  14. descended from Apple Sample Code, but that you've made changes.
  15.  
  16. *************************************************************************************/
  17.  
  18.  
  19. #ifndef __ISPPLUGINUI__
  20. #define __ISPPLUGINUI__
  21.  
  22. #ifndef __MACTYPES__
  23. #include <MacTypes.h>
  24. #endif
  25.  
  26. #ifndef __EVENTS__
  27. #include <Events.h>
  28. #endif
  29.  
  30. #ifndef __DIALOGS__
  31. #include <Dialogs.h>
  32. #endif
  33.  
  34. #ifndef __INPUTSPROCKET__
  35. #include <InputSprocket.h>
  36. #endif
  37.  
  38. #include "InputSprocketDriver.h"
  39.  
  40. enum { kMenuID_TempMenu = -1 };
  41.  
  42. // plugin string list
  43. enum
  44. {
  45.     kStrList_PlugInUI = 50,
  46.     kStrList_PlugInUI_None = 1
  47. };
  48.  
  49. // 'isei' resources
  50. enum
  51. {
  52.     kElementConfigResource_BlankDPad         = 128,
  53.     kElementConfigResource_DPad1             = 129,
  54.     kElementConfigResource_BlankButton         = 130,
  55.     kElementConfigResource_Button1             = 131,
  56.     kElementConfigResource_SymetricAxis     = 132,    
  57.     kElementConfigResource_AsymetricAxis     = 133,
  58.     kElementConfigResource_Delta            = 134,
  59.     kElementConfigResource_Button2            = 135
  60. };
  61.  
  62. // classs definition
  63. class ISpPlugInUI
  64. {
  65. public:
  66.     ISpPlugInUI (void);
  67.     
  68.     // these must be overridden in the subclass
  69.     virtual OSStatus Init(    UInt32 count, 
  70.                             ISpNeed needs[], 
  71.                             ISpElementReference virtualElements[],
  72.                             Boolean used[],
  73.                             OSType appCreatorCode,
  74.                             OSType subCreatorCode, 
  75.                             UInt32 stateLength,
  76.                             void *state) = 0;
  77.     virtual OSStatus Stop(void) = 0;
  78.     virtual OSStatus GetSize(Point &minimum, Point &best) = 0;
  79.     virtual OSStatus HandleEvent(EventRecord &theEvent, Boolean &handled) = 0;
  80.     virtual OSStatus Show(DialogPtr theDialog, short dialogItemNumber, Rect &r) = 0;
  81.     virtual OSStatus Hide(void) = 0;
  82.     virtual OSStatus BeginConfiguration(UInt32 count, ISpNeed needs[]) = 0;
  83.     virtual OSStatus EndConfiguration(Boolean accept) = 0;
  84.     virtual OSStatus GetIcon(short &iconSuiteResourceId) = 0;
  85.     virtual OSStatus GetState(UInt32 buflen, void *buffer, UInt32 &length) = 0;
  86.     virtual OSStatus SetState(UInt32 length, void *buffer) = 0;
  87.     virtual OSStatus Dirty(Boolean &dirty);
  88.     virtual OSStatus SetActive(Boolean active) = 0;
  89.     virtual OSStatus DialogItemHit(short itemHit) = 0;
  90.     
  91.     // 1.03 or later stuff
  92.     virtual OSStatus Tickle(void) = 0;
  93.     virtual OSStatus InterruptTickle(void) = 0;
  94.     virtual OSStatus Draw(void) = 0;
  95.     virtual OSStatus Click(const EventRecord &event) = 0;
  96.  
  97.     // 1.2 or later stuff
  98.     virtual OSStatus ADBReInit(Boolean inPostProcess) = 0;
  99.  
  100.     // metahandler
  101.     static ISpDriverFunctionPtr_Generic MetaHandler(UInt32 refCon, ISpMetaHandlerSelector selector);
  102.     
  103.     // common UI
  104. protected:
  105.     enum {         kUnsetIndex = 0xffff0001         };
  106.     
  107.     //    !!!    ISpDriverBase has descended from ISPPlugInUI and handles everything that has been
  108.     //    !!!    recently added to this class, and much more.  These classes need to be reconciled
  109.     //    !!! but for now, this eliminates duplicated member caruables
  110.     ISpElementReference *    mReferences;
  111.     ISpNeed *                mNeeds;
  112.     UInt32                     mNumNeeds;
  113.  
  114.     DialogPtr                mDialog;
  115.     short                     mBaseDITLCount;
  116.     
  117.     Boolean                 mDirty;
  118.  
  119.     virtual UInt32 *     GetDialogItemToNeedMapping () = 0;
  120.     virtual void         SetVirtualElements (void) = 0;    // was SetFromIndex
  121.     virtual    Boolean        IsPressed (short inDialogItem) {inDialogItem; return false;};    // is this dialog item 'pressed' (ie on the device)
  122.     
  123.     public:
  124.         typedef enum
  125.         {
  126.             kDirection_None,
  127.             kDirection_X,
  128.             kDirection_Y,
  129.             kDirection_Z,
  130.             kDirection_Rx,
  131.             kDirection_Ry,
  132.             kDirection_Rz,
  133.  
  134.             kDirection_Roll     = kDirection_Rz,
  135.             kDirection_Pitch     = kDirection_Rx,
  136.             kDirection_Yaw         = kDirection_Ry
  137.         } DirectionType;
  138.         
  139.         static DirectionType GetDirection2D(ISpElementLabel label);
  140.         static DirectionType GetDirection(ISpElementLabel label);
  141.  
  142.     private:
  143.         Boolean CheckPopUpHit(
  144.                 Point                inWhere,
  145.                 short                inDialogItem,
  146.                 ISpElementKind        elementKind,
  147.                 ISpElementLabel     elementLabel,
  148.                 ISpElementKind        *validKinds,
  149.                 UInt32                numKinds,
  150.                 UInt32                inNeed,
  151.                 UInt32                &outNeed);
  152.  
  153.  
  154.         Boolean IsAppropriateNeedForButton(
  155.                 ISpNeed &        need,
  156.                 ISpElementLabel    buttonLabel);
  157.  
  158.         Boolean IsAppropriateNeedForDPad(
  159.                 ISpNeed &        need,
  160.                 ISpElementLabel    dpadLabel);
  161.  
  162.         Boolean IsAppropriateNeedForAxis(
  163.                 ISpNeed &        need,
  164.                 ISpElementLabel    axisLabel);
  165.  
  166.         Boolean IsAppropriateNeedForDelta(
  167.                 ISpNeed &        need,
  168.                 ISpElementLabel    deltaLabel);
  169.  
  170.         Boolean IsAppropriateNeed(
  171.                 ISpNeed &        need,
  172.                 ISpElementKind    elementKind,
  173.                 ISpElementLabel elementLabel);
  174.         
  175. protected:
  176.         void SetDialogControl(
  177.             short                inRelDialogItem,
  178.             short                inValue);
  179.  
  180.         void PlotPopupIcon(
  181.                 short                inItem,
  182.                 IconTransformType    inTransform);
  183.     
  184.         void HandleStickClick (
  185.                 Point                where,
  186.                 short                dialogItem,
  187.                 UInt32                upDialogItem,
  188.                 UInt32                downDialogItem,
  189.                 UInt32                leftDialogItem,
  190.                 UInt32                rightDialogItem,
  191.                 UInt32                oldNeed,
  192.                 UInt32                &newNeed);
  193.  
  194.         void HandleMouseClick (
  195.                 Point                where,
  196.                 short                dialogItem,
  197.                 UInt32                upDialogItem,
  198.                 UInt32                downDialogItem,
  199.                 UInt32                leftDialogItem,
  200.                 UInt32                rightDialogItem,
  201.                 UInt32                oldNeed,
  202.                 UInt32                &newNeed);
  203.                 
  204.         void HandleDeltaClick (
  205.                 Point                where,
  206.                 short                dialogItem,
  207.                 ISpElementLabel        elementLabel,
  208.                 UInt32                minDeltaDialogItem,
  209.                 UInt32                maxDeltaDialogItem,
  210.                 UInt32                oldNeed,
  211.                 UInt32                &newNeed);
  212.                 
  213.         void HandleAxisClick (
  214.                 Point                where,
  215.                 short                dialogItem,
  216.                 ISpElementLabel        elementLabel,
  217.                 UInt32                minAxisDialogItem,
  218.                 UInt32                maxAxisDialogItem,
  219.                 UInt32                oldNeed,
  220.                 UInt32                &newNeed);
  221.  
  222.         void HandlePedalAxisClick (
  223.                 Point                where,
  224.                 short                dialogItem,
  225.                 ISpElementLabel        elementLabel,
  226.                 UInt32                oldNeed,
  227.                 UInt32                &newNeed);
  228.  
  229.         void HandleButtonClick (
  230.                 Point                where,
  231.                 short                dialogItem,
  232.                 ISpElementLabel        elementLabel,
  233.                 UInt32                oldNeed,
  234.                 UInt32                &newNeed);
  235.  
  236.         void HandleDPadClick (
  237.                 Point                where,
  238.                 short                dialogItem,
  239.                 UInt32                upDialogItem,
  240.                 UInt32                downDialogItem,
  241.                 UInt32                leftDialogItem,
  242.                 UInt32                rightDialogItem,
  243.                 UInt32                oldNeed,
  244.                 UInt32                &newNeed);
  245.                 
  246.  
  247. private:
  248.     static OSStatus MHInit(    UInt32 refCon,
  249.                             UInt32 count, 
  250.                             ISpNeed needs[], 
  251.                             ISpElementReference virtualElements[],
  252.                             Boolean used[],
  253.                             OSType appCreatorCode,
  254.                             OSType subCreatorCode, 
  255.                             UInt32 reserved,
  256.                             void* reserved2);
  257.     static OSStatus MHStop(UInt32 refCon);
  258.     static OSStatus MHGetSize(UInt32 refCon, Point *minimum, Point *best);
  259.     static OSStatus MHHandleEvent(UInt32 refCon, EventRecord *theEvent, Boolean *handled);
  260.     static OSStatus MHShow(UInt32 refCon, DialogPtr theDialog, short dialogItemNumber, Rect *r);
  261.     static OSStatus MHHide(UInt32 refCon);
  262.     static OSStatus MHBeginConfiguration(UInt32 refCon, UInt32 count, ISpNeed needs[]);
  263.     static OSStatus MHEndConfiguration(UInt32 refCon, Boolean accept);
  264.     static OSStatus MHGetIcon(UInt32 refCon, short *iconSuiteResourceId);
  265.     static OSStatus MHGetState(UInt32 refCon, UInt32 buflen, void *buffer, UInt32 *length);
  266.     static OSStatus MHSetState(UInt32 refCon, UInt32 length, void *buffer);
  267.     static OSStatus MHDirty(UInt32 refCon, Boolean *dirty);
  268.     static OSStatus MHSetActive(UInt32 refCon, Boolean active);
  269.     static OSStatus MHDialogItemHit(UInt32 refCon, short itemHit);
  270.     
  271.     // 1.03 or later stuff
  272.     static OSStatus MHTickle(UInt32 refCon);
  273.     static OSStatus MHInterruptTickle(UInt32 refCon);
  274.     static OSStatus MHDraw(UInt32 refCon);
  275.     static OSStatus MHClick(UInt32 refCon, const EventRecord *event);
  276.     
  277.     // 1.2 or later stuff
  278.     static OSStatus MHADBReInit(UInt32 refCon, Boolean inPostProcess);
  279.     
  280. #if FORCE_FB
  281.     //•    Force Effect Functions
  282.     static OSStatus MHBuffeting(UInt32 refCon, UInt32 inMagnitude);
  283.     static OSStatus MHBuffetingClear(UInt32 refCon);
  284.     static OSStatus MHButtonReflexJolt(UInt32 refCon, UInt32 inButton, UInt32 inMagnitude, SInt32 inDirection, UInt32 inDuration, UInt32 inRepeatRate);
  285.     static OSStatus MHButtonReflexClear(UInt32 refCon, UInt32 inButton);
  286.     static OSStatus MHJolt(UInt32 refCon, UInt32 inMagnitude, SInt32 inDirection, UInt32 inDuration);
  287.     static OSStatus MHXVibration(UInt32 refCon, UInt32 inLeftMagnitude, UInt32 inRightMagnitude, UInt32 inFrequency);
  288.     static OSStatus MHXVibrationClear(UInt32 refCon);
  289.     static OSStatus MHYVibration(UInt32 refCon, UInt32 inUpMagnitude, UInt32 inDownMagnitude, UInt32 inFrequency);
  290.     static OSStatus MHYVibrationClear(UInt32 refCon);
  291.     static OSStatus MHVectorForce(UInt32 refCon, UInt32 inMagnitude, SInt32 inDirection);
  292.     static OSStatus MHVectorForceClear(UInt32 refCon);
  293.     static OSStatus MHXYVectorForce(UInt32 refCon, SInt32 inXMagnitude, SInt32 inYMagnitude);
  294.     static OSStatus MHXSpring(UInt32 refCon, SInt32 inOrigin, UInt32 inLeftStiffness, UInt32 inRightStiffness);
  295.     static OSStatus MHXSpringClear(UInt32 refCon);
  296.     static OSStatus MHYSpring(UInt32 refCon, SInt32 inOrigin, UInt32 inUpStiffness, UInt32 inDownStiffness);
  297.     static OSStatus MHYSpringClear(UInt32 refCon);
  298. #endif
  299.     
  300.     unsigned long thumbprint;
  301.     
  302.     enum
  303.     {
  304.         kThumbprint = 'ispx'
  305.     };
  306. };
  307.  
  308. OSStatus CreateDeviceFromResource(    short resId, 
  309.                                     UInt32 refCon,
  310.                                     ISpDeviceReference &device);
  311.  
  312. OSStatus CreateElementFromResource(    short elementResId, 
  313.                                     short configResID, 
  314.                                     ISpDeviceReference device, 
  315.                                     ISpElementReference &element);
  316.  
  317. void     MakeDialogItemInvisable (DialogRef theDialog, short itemNo);
  318. Boolean    DialogItemIsInvisable (DialogRef theDialog, short itemNo);
  319. void    SetDialogItemWidth (DialogRef theDialog, short itemNo, short width);
  320.  
  321. enum
  322. {
  323.     kAxisAsButton_Left    = 0,
  324.     kAxisAsButton_Right    = 1,
  325.     kAxisAsButton_Down    = 0,
  326.     kAxisAsButton_Up    = 1,
  327.     kAxisAsButton_Min    = 0,
  328.     kAxisAsButton_Max    = 1
  329. };
  330.  
  331. void    AxisToButtons(UInt32 axis, UInt32 buttons[2]);    //SetAxisButtons
  332. void    PedalAxisToButton(UInt32 axis, UInt32 & button);//PedalAxisToButton
  333. UInt32    AxisToDPad(UInt32 xAxis, UInt32 yAxis);    //SetAxisDPad
  334. UInt32    BooleanDirectionsToDPad(UInt32 up, UInt32 left, UInt32 down, UInt32 right);
  335. UInt32    DigitalAxisToDPad(SInt8 x, SInt8 y);
  336. void    DPadToButtonsAndAxis(UInt32 dpad, UInt32 buttons[4], UInt32 axis[2]);//SetDPadAsButtonsAndAxis
  337. UInt32    DPadReverseVertical(UInt32 dpad);
  338.  
  339. #endif /* __ISPPLUGINUI__ */
  340.